package com.example.gymmanagebackend.mapper;

import com.example.gymmanagebackend.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {

    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    @Insert("INSERT INTO users (username, password, identify) VALUES (#{username}, #{password}, #{identify})")
    int addUser(User user);

    @Delete("DELETE FROM users WHERE id = #{id}")
    int deleteUserById(Integer id);


    @Select("SELECT * FROM users")
    List<User> getAllUsers();

    @Select("SELECT * FROM users WHERE id = #{id}")
    User findUserById(Integer id);

    @Select("SELECT * FROM users WHERE username = #{username}")
    User findUserByUsername(@Param("username") String username);

    @Delete("DELETE FROM users WHERE username = #{username}")
    int deleteUserByUsername(@Param("username") String username);

    @Update("UPDATE users SET password = #{password} WHERE username = #{username}")
    int updateUser(User user);
}